package controler;


import java.io.Serializable;
import java.util.Collection;

import view.ListView;
import ema.tpjee.banking.session.SessionFacade;
import ema.tpjee.pojo.banking.model.Bank;



public class BankControler implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -1645348478746136298L;
	//private BankApplicationDaoImpl dao_;


	private SessionFacade sessionFacade;

	
	
	public BankControler() {
		super();
		System.out.println("creating BankControler");
	}

	public Collection<Bank> getList() {
		return sessionFacade.getBankDao().getList();
	}

	public void setList(Collection<Bank> dumm) {

	}

	public void setView(ListView dumm) {
		//this.view = view;
	}
	
	public void add(Bank b) {
		sessionFacade.getBankDao().add(b);
	}
	
	public String cancel() {
		System.out.println("action "+this.getClass().getName()+" cancel()");
		return "list";
	}
	

	
	public String save(){
		System.out.println("action "+this.getClass().getName()+" save()");
		//implicit commit by lifecycle, validators will work
		return "list";
	}
	
	public String delete(){
		System.out.println("action "+this.getClass().getName()+" delete()");	
		sessionFacade.deleteBank();
		return "list";
	}	
	
	public String edit() {
		System.out.println("action "+this.getClass().getName()+" edit()");
		int bankId=sessionFacade.getCurrentBank().getId();//sessionFacade.getBankView().getIdCmdValue();
		System.out.println(bankId);
		//sessionFacade.findBank(Integer.parseInt(bankId));
		//sessionFacade.setCurrentBank(sessionFacade.getBankDao().find(Integer.parseInt(bankId)));
		return "edit";
	}
	
	public String create() {
		System.out.println("action "+this.getClass().getName()+" create()");
		sessionFacade.newBank();
		return "edit";
	}
	

	
	public String showCustomers() {
		System.out.println("action "+this.getClass().getName()+" showCustomers()");
		return "customers";
	}

	
	
	public String next() {
		System.out.println("action "+this.getClass().getName()+" next()");
		sessionFacade.setCurrentBank(sessionFacade.getBankDao().next((sessionFacade.getCurrentBank())));
		return "edit";
	}
	
	public String prior() {
		System.out.println("action "+this.getClass().getName()+" prior()");
		//sessionFacade.setCurrentBank(nextCustomer(sessionFacade.getCurrentBank()));
		sessionFacade.setCurrentBank(sessionFacade.getBankDao().prior((sessionFacade.getCurrentBank())));
		return "edit";
	}
	public String copy() {
		System.out.println("action "+this.getClass().getName()+" copy()");
		sessionFacade.setCurrentBank(sessionFacade.getBankDao().clone((sessionFacade.getCurrentBank())));
		return "list";
	}
	

	
	public String foobar() {
		System.out.println("action "+this.getClass().getName()+" foobar()");
		return "edit";
	}
		
	
	public void setSessionFacade(SessionFacade sf) {
		this.sessionFacade=sf;	
		System.out.println(this.getClass().getName()+" setSessionFacade");
	}


}
